07. DBW Node

DBW Node Overview

Once messages are being published to /final_waypoints , the vehicle's waypoint follower will publish twist commands to the /twist_cmd topic. The goal for this part of the project is to implement the drive-by-wire node ( dbw_node.py ) which will subscribe to /twist_cmd and use various controllers to provide appropriate throttle, brake, and steering commands. These commands can then be published to the following topics:

  • /vehicle/throttle_cmd
  • /vehicle/brake_cmd
  • /vehicle/steering_cmd

Since a safety driver may take control of the car during testing, you should not assume that the car is always following your commands. If a safety driver does take over, your PID controller will mistakenly accumulate error, so you will need to be mindful of DBW status. The DBW status can be found by subscribing to /vehicle/dbw_enabled .

When operating the simulator please check DBW status and ensure that it is in the desired state. DBW can be toggled by clicking "Manual" in the simulator GUI.

All code necessary to implement the drive-by-wire node can be found in the package:

(path_to_project_repo)/ros/src/twist_controller

Twist controller package files

Within the twist controller package, you will find the following:

  • dbw_node.py

    This python file implements the dbw_node publishers and subscribers. You will need to write ROS subscribers for the /current_velocity , /twist_cmd , and /vehicle/dbw_enabled topics. This file also imports the Controller class from twist_controller.py which will be used for implementing the necessary controllers. The function used to publish throttle, brake, and steering is publish .

    Note that throttle values passed to publish should be in the range 0 to 1, although a throttle of 1 means the vehicle throttle will be fully engaged. Brake values passed to publish should be in units of torque (N*m). The correct values for brake can be computed using the desired acceleration, weight of the vehicle, and wheel radius.

  • twist_controller.py

    This file contains a stub of the Controller class. You can use this class to implement vehicle control. For example, the control method can take twist data as input and return throttle, brake, and steering values. Within this class, you can import and use the provided pid.py and lowpass.py if needed for acceleration, and yaw_controller.py for steering. Note that it is not required for you to use these, and you are free to write and import other controllers.

  • yaw_controller.py

    A controller that can be used to convert target linear and angular velocity to steering commands.

  • pid.py

    A generic PID controller that can be used in twist_controller.py .

  • lowpass.py

    A generic low pass filter that can be used in twist_controller.py .

  • dbw_test.py

    You can use this file to test your DBW code against a bag recorded with a reference implementation.
    The bag can be found at https://s3-us-west-1.amazonaws.com/udacity-selfdrivingcar/files/reference.bag.zip

    Detailed use instructions can be found in the dbw_test.py file.

Testing with the simulator

Highway

At this point in the project, it is unnecessary to use camera data. If you are experiencing system latency or dropped ROS messages, be sure to keep the camera toggle unchecked in the first test track in the simulator.

Test Lot

The CarND-Capstone/ros/src/waypoint_loader/launch/waypoint_loader.launch file is set up to load the waypoints for the first track. To test using the second track, you will need to change

<param name="path" value="$(find styx)../../../data/wp_yaw_const.csv" />

to use the churchlot_with_cars.csv as follows:

<param name="path" value="$(find styx)../../../data/churchlot_with_cars.csv"/>

Note that the second track does not send any camera data.

Important:

dbw_node.py is currently set up to publish steering, throttle, and brake commands at 50hz. The DBW system on Carla expects messages at this frequency, and will disengage (reverting control back to the driver) if control messages are published at less than 10hz. This is a safety feature on the car intended to return control to the driver if the software system crashes. You are welcome to modify how the dbw_node.py code is structured, but please ensure that control commands are published at 50hz.

Additionally, although the simulator displays speed in mph, all units in the project code use the metric system, including the units of messages in the /current_velocity topic (which have linear velocity in m/s).

Finally, Carla has an automatic transmission, which means the car will roll forward if no brake and no throttle is applied. To prevent Carla from moving requires about 700 Nm of torque.